<?php

Route::get('/', 'HomeController@index')->name('home');

Route::post('/', function () {
    // ip地址被各种扫
    return response('404', 404);
});

Route::group(['middleware' => 'gitlab.auth'], function () {
    //    Route::get('deploy/{server_type}/{project_id}', 'HomeController@deploy');

    Route::get('deploy/batch', 'DeployController@batch');
    Route::get('deploy/{project_id}', 'DeployController@show');
    Route::get('deploy/{project_id}/batch', 'DeployController@projectBatch');
    Route::post('deploy/load_diff/{project_id}', 'DeployController@loadDiff');
    Route::post('web_deploy', 'DeployController@webDeploy');
    Route::post('batch_deploy', 'DeployController@batchDeploy');

    Route::post('auth/logout', function () {
        Auth::logout();

        return back();
    });

    Route::group(['prefix' => 'role'], function () {
        Route::get('/', 'RoleController@index');
        Route::get('/set', 'RoleController@set');
        Route::get('/create', 'RoleController@create');
    });

    Route::group(['prefix' => 'permission'], function () {
        Route::get('/', 'PermissionController@index');
        Route::any('/set/{project_id}-{setting_id}', 'PermissionController@set');
        Route::get('/update/{server_type}/{project_id}/{user_id}/', 'PermissionController@update');
        Route::get('/create', 'PermissionController@create');
    });

    Route::group(['prefix' => 'logs'], function () {
        Route::get('/{server_type}/{project_id}', 'LogsController@show');
        Route::get('/', 'LogsController@index');
    });

    Route::get('clear_project_cache', 'HomeController@clearProjectCache');

    Route::group(['prefix' => 'project', 'middleware' => 'owner-only'], function () {
        Route::get('create/{project_id}', 'ProjectController@create');
        Route::post('save', 'ProjectController@save');
        Route::get('show/{project_id}', 'ProjectController@show');
        Route::get('branches/{project_id}', 'ProjectController@branches');
        Route::get('remove/{project_id}-{setting_id}', 'ProjectController@remove');
        Route::get('clone/{project_id}-{setting_id}', 'ProjectController@cloneSetting');
        Route::get('edit/{project_id}-{setting_id}', 'ProjectController@edit');
        Route::post('update/{setting_id}', 'ProjectController@update');
    });
});

Route::group(['middleware' => 'gitlab.hook.auth'], function () {
    Route::post('deploy', 'DeployController@hookDeploy');
});

Route::get('callback', 'GitLabController@callback');
Route::get('auth', 'GitLabController@auth')->name('auth');

Route::post('login', 'HomeController@login');
